import api from '../../utils/api.js';
import config from '../../config.js';
// pages/game/game.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    url:"",
    port:"",
    themeSite:{}
  },
  //解析链接
  getQueryString: function (url, name) {
    var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
    var r = url.substr(1).match(reg);
    if (r != null) {
      return r[2];
    }
    return null;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let id = '';
    if (options.id) { //微信内部扫一扫
      id = options.id;
    } else if (options.q) { //微信内部扫一扫
      const scan_url = decodeURIComponent(options.q)
      id = self.getQueryString(scan_url, 'id')
    } else if (options.scene != undefined) { //微信直接扫码 
      const scan_url = decodeURIComponent(options.scene)
      id = self.getQueryString(scan_url, 'id')
    } 
    let self=this;
    self.setData({
      id:id,
     });
    api.getThemeProjectData({
      method: "GET",
      data: {
        id: id,
        uuid: "test",
        device:"wx",
        token:"12212121"
      },
      success: (res) => { 
          const response = res.data;
          console.log(response);
          if (response.code == '200' && response.data) {  
            let config=response.data.config;
            let privateHost="https://t6.thago.cn/parkview"
            if(config.privateHost){ 
              privateHost=config.privateHost;
            }   
            let url =privateHost+response.data.url;
              self.setData({
                url:url,
                id:response.data.id,
                url:url,
                themeSite:response.data
              }) 
          } 
      }
  });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.setData({
      url:"",
     });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: this.data.themeSite.name,
      desc: this.data.themeSite.remark,
      path: 'pages/views/view?id=' + this.data.themeSite.id,
    }
  }
})